package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.util.TimestampIdGenerator;
import com.ruoyi.util.backCard.BankCardUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BankMapper;
import com.ruoyi.system.domain.Bank;
import com.ruoyi.system.service.IBankService;

/**
 * 银行卡Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-14
 */
@Service
public class BankServiceImpl implements IBankService 
{
    @Autowired
    private BankMapper bankMapper;

    /**
     * 查询银行卡
     * 
     * @param userId 银行卡主键
     * @return 银行卡
     */
    @Override
    public Bank selectBankByUserId(Long userId)
    {
        return bankMapper.selectBankByUserId(userId);
    }

    /**
     * 查询银行卡列表
     * 
     * @param bank 银行卡
     * @return 银行卡
     */
    @Override
    public List<Bank> selectBankList(Bank bank)
    {
        return bankMapper.selectBankList(bank);
    }

    /**
     * 新增银行卡
     * 
     * @param bank 银行卡
     * @return 结果
     */
    @Override
    public int insertBank(Bank bank)
    {
        bank.setAddTime(TimestampIdGenerator.getCurrentDateTime());
        String s = BankCardUtil.identifyBank(bank.getBankCard());
        System.out.println(s);
        bank.setBankName("中国银行");
        return bankMapper.insertBank(bank);
    }

    /**
     * 修改银行卡
     * 
     * @param bank 银行卡
     * @return 结果
     */
    @Override
    public int updateBank(Bank bank)
    {
        return bankMapper.updateBank(bank);
    }

    /**
     * 批量删除银行卡
     * 
     * @param userIds 需要删除的银行卡主键
     * @return 结果
     */
    @Override
    public int deleteBankByUserIds(Long[] userIds)
    {
        return bankMapper.deleteBankByUserIds(userIds);
    }

    /**
     * 删除银行卡信息
     * 
     * @param userId 银行卡主键
     * @return 结果
     */
    @Override
    public int deleteBankByUserId(Long userId)
    {
        return bankMapper.deleteBankByUserId(userId);
    }
}
